ele;<template>
  <div class="login-body">
    <el-form :model="loginForm" class="login-form">
      <h1 class="login-title">欢迎登录！</h1>
      <el-form-item>
        <el-input
          type="input"
          placeholder="请输入账号"
          v-model="loginForm.username"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          type="password"
          placeholder="请输入密码"
          v-model="loginForm.password"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin()" class="login-button"
          >登录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang='ts'>
import { ref, reactive, getCurrentInstance } from "vue";
import { useAllDataStore } from "@/stores";
import { useRouter } from "vue-router";
interface LoginFormData {
  username: string;
  password: string;
}
const loginForm: LoginFormData = reactive({
  username: "",
  password: "",
});
const { proxy } = getCurrentInstance() as any;
const router = useRouter();
const store = useAllDataStore();
const handleLogin = async () => {
  const res = await proxy.$api.getMenu(loginForm);
  if (res) {
    //在这里执行updateMenuList，传入res.menuList
    store.updateMenuList(res.menuList);
    //直接修改token
    store.state.token = res.token;
    store.addMenu(router);
    router.push("/home");
  }
};
</script>

<style scoped>
.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
  background-color: #f0f2f5;
  background-image: url(../assets/images/background.png);
  background-size: 100%;
  overflow: hidden;
}
.login-title {
  text-align: center;
  margin-bottom: 25px;
  margin-top: 12px;
}

.login-form {
  width: 350px;
  padding: 20px;
  border-radius: 5px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  border-radius: 15px;
  box-shadow: 0 0 25px #cacaca;
}
.login-button {
  margin: 16px auto 0;
}
</style>